package com.xjgc.msibase.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjgc.msibase.entity.MsiServerRecord;
import com.xjgc.msibase.mapper.MsiServerRecordInfoMapper;
import com.xjgc.msibase.mapper.MsiServerRecordMapper;
import com.xjgc.msibase.service.IMsiServerRecordService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 实时接口传输记录
 *
 * @author: 小逗号
 * @date: 2023-9-27
 * @description:
 * @since:
 */
@Slf4j
@Service
public class MsiServerRecordServiceImpl
        extends ServiceImpl<MsiServerRecordMapper, MsiServerRecord>
        implements IMsiServerRecordService {
    @Resource
    private MsiServerRecordInfoMapper msiServerRecordInfoMapper;

    @Override
    public MsiServerRecord getRecord(MsiServerRecord record) {
        MsiServerRecord byId = this.getById(record.getId());
        return byId;
    }

    @Override
    public void addRecord(MsiServerRecord record, String requestText) {
        record.setRequestText(requestText);
        this.save(record);
    }

    @Override
    public void updateResponse(MsiServerRecord record, String responseText) {
        record.setResponseText(responseText);
        this.updateById(record);
    }

    @Override
    public IPage<MsiServerRecord> pageList(IPage<MsiServerRecord> page, MsiServerRecord queryAo) {
        return baseMapper.selectPageList(page, queryAo);
    }

    @Override
    public void deleteTimer() {
        Date date = DateUtils.addMonths(new Date(), -1);
        log.info("中间库记录定时清理");
        baseMapper.deleteTimer(date);
        log.info("中间库记录明细定时清理");
        msiServerRecordInfoMapper.deleteTimer(date);
    }
}
